package com.efuture.vdrp.android.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class EmployeesServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("gbk");
		response.setCharacterEncoding("gbk");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		String action = request.getParameter("action");
		ArrayList list = new ArrayList();
		MySQL my = new MySQL();
		if (action.trim().equals("selectname")) {
			list = my.getemployeename();
			for (int i = 0; i < list.size(); i++) {
				out.println(list.get(i));
				out.flush();
			}
		} else if (action.trim().equals("employeeadd")) {
			String name = request.getParameter("name").trim();
			String pwd = request.getParameter("pwd").trim();
			String phone = request.getParameter("phone").trim();
			String qx = request.getParameter("qx").trim();
			String str = my.employeeadd(name, pwd, phone, qx);
			out.println(str);
			out.flush();
		}else if(action.trim().equals("employeedel")){
			String name=request.getParameter("name").trim();
			String str=my.employeedel(name);
			out.println(str);
			out.flush();
		}
		else if(action.trim().equals("selectall")){
			String name=request.getParameter("name").trim();
			HashMap map=new HashMap();
			map=my.selectemployeeall(name);
			net.sf.json.JSONObject mapjson = net.sf.json.JSONObject.fromObject(map);
			out.println(mapjson);
			out.flush();
		}
		else if(action.trim().equals("employeeaupdate")){
			String name = request.getParameter("name").trim();
			String pwd = request.getParameter("pwd").trim();
			String phone = request.getParameter("phone").trim();
			String qx = request.getParameter("qx").trim();
			String str = my.employeeupdate(name, pwd, phone, qx);
			out.println(str);
			out.flush();
		}
		out.close();
		my.close();

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
